home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
050
/
madtrb38.arc
/
ALT.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1986-02-08
|
5KB
|
89 lines
program Alt_Key; { Accepts an alpha or numeric command line parameter,
producing a simulated keyboard input of the
corresponding Alt-key combination.
e.g. entering... alt P <CR> at the DOS command
prompt will produce the effect of pressing <Alt><P>.
The purpose is to permit the activation of Super Key
or similar keyboard macros from within batch files.
The Key_In procedure can be included in Turbo programs
thus permiting you to activate Super Key macros without
requiring the user to press a key. }
{ These routines are hardware dependent and work only on IBM-PC compatibles.
They require Turbo 3.0 or later due to the use of ParamCount and ParamStr.
If you are using an earlier version of Turbo you could write your own
routines to produce the same effect. }
procedure Clr_Kbd_Buf;
var kbd_head : Byte absolute $0000:$041A;
var kbd_tail : Byte absolute $0000:$041C;
begin
kbd_head := kbd_tail;
end; { Clr_Kbd_Buf }
procedure Key_In(in_chr: Integer);
var bool_val : Boolean;
{ Causes a character to be received as if a key had been pressed.
in_chr is an integer representing the character to be received.
If the character is an ASCII character or part of the extended
character set (#128..#255) the integer will be in the range
0..255. If a `special' key, function key or Alt key combination
is to be received in_chr should equal the scan code of the
desired key * 256. e.g. The scan code for <Alt><1> is 120 decimal
$78 hex, so in_chr should be 30720 decimal or $7800 hex to produce
the effect of pressing <Alt><1>. }
begin
Clr_Kbd_Buf; { Make sure buffer is empty. Optional depending on }
inline { application. }
($1E/ { PUSH DS Save DS and change it }
$B8/$40/$00/ { MOV AX,0040 to point to seg 0040: }
$8E/$D8/ { MOV DS,AX }
$FA/ { CLI Clear interrupt flag }
$8B/$46/$04/ { MOV AX,[BP+04] Move character to AX }
$8B/$1E/$1C/$00/ { MOV BX,[001Ch] Move kb buf tail Ofs to BX }
$89/$07/ { MOV [BX],AX Put character in buffer. }
$83/$C3/$02/ { ADD BX,+2 Increment tail pntr by 2. }
$3B/$1E/$82/$00/ { CMP BX,[0082h] Compare BX with [0040:0082]}
$74/$07/ { JZ CIRC Jump if end of buffer. }
$89/$1E/$1C/$00/ { MOV [001Ch],BX Update address of tail. }
$EB/$09/$90/ { JMP EXIT Exit }
$8B/$1E/$80/$00/ {CIRC: MOV BX,[0080h] Set BX to start of buffer. }
$89/$1E/$1C/$00/ { MOV [001Ch],BX Update address of tail. }
$FB/ {EXIT: STI Set interrupt flag. }
$1F); { POP DS Restore DS. }
bool_val := KeyPressed; { Force Turbo to check for a keyboard input. }
end; { Key_In }
const alt_alpha : string[35] = 'QWERTYUIOP ASDFGHJKL ZXCVBNM';
alt_num : string[10] = '1234567890';
var param_chr : Char;
alt_keys : set of Char;
{ As shown the ALT command will only accept parameters consisting of the
alpha charater set and the numbers 0..9. The resulting keyboard input
generated will be the Alt key in combination with the parameter. The
Key_In procedure can produce function key combinations and the `special'
keys (e.g. Ins, Home etc.), however it is not as easy to represent these
keys with a DOS command line entry. }
begin { Alt_Key }
alt_keys := (['A'..'Z'] + ['0'..'9']);
if (ParamCount = 1) then { Proceed if there is exactly one cmd line param.}
begin
param_chr := ParamStr(1); param_chr := UpCase(param_chr);
if (param_chr in alt_keys) then
if (Pos(param_chr,alt_num) > 0) then
Key_In((Pos(param_chr,alt_num) + 119) * 256)
else
Key_In((Pos(param_chr,alt_alpha) + 15) * 256)
end
else
WriteLn('A single character parameter is required. (A-Z or 0-9)');
end. { Alt_Key }